using System;
using System.Collections.Generic;
using System.Text;

namespace My.IdlConverter.Core.Types
{
    public class TypeBase : IType
    {
        private string _typeString;
        private string _origin;
        private object _parent;
        private TypeMap _substitution;
        private IList<IType> _subtypes = new List<IType>();

        public TypeBase()
        {
        }

        public TypeBase(string typeString, TypeMap substitution)
        {
            _typeString = typeString;
            _substitution = substitution;
        }

        public string PureTypeString
        {
            get
            {
                return TypeString.Replace("const", "").Replace("*", "").Replace("&","").Trim();
            }
        }

        public virtual string TypeString
        {
            get
            {
                return _typeString;
            }
            set
            {
                _typeString = value;
            }
        }

        public string Origin
        {
            get
            {
                return _origin;
            }
            set
            {
                _origin = value;
            }
        }

        public bool Const
        {
            get
            {
                return (_typeString.IndexOf("const") != -1);
            }
        }

        public bool Ref
        {
            get
            {
                if (_typeString.IndexOf("Iv_Object") != -1)
                    return (_typeString.IndexOf("**") != -1);
                else
                    return ((_typeString.IndexOf('&') != -1) || (_typeString.IndexOf('*') != -1));
            }
        }

        public bool ConstRef
        {
            get
            {
                return (Const && Ref);
            }
        }

        public bool AbsoluteRef
        {
            get
            {
                return (!Const && Ref);
            }
        }

        public bool AbosluteConst
        {
            get
            {
                return (Const && !Ref);
            }
        }

        public IList<IType> SubTypes
        {
            get
            {
                return _subtypes;
            }
        }

        public TypeMap Substitution
        {
            get
            {
                return _substitution;
            }
            set
            {
                _substitution = value;
            }
        }

        public object Parent
        {
            get
            {
                return _parent;
            }
            set
            {
                _parent = value;
            }
        }
    }
}
